<?php
$req_path = "../";
require_once($req_path . "includes/ini.php");
require_once($req_path . "includes/db.php");

class M_Stock extends DB {

    private $rowCount = 0;
    public $table_name = "tb_request";
    public $table_detail = "tb_request_detail";

    function M_Stock() {
        parent::__construct();
    }

    function getRunning($t) {
        $_str = substr((543 + date('Y')) . date('m'), -4);

        $sql = " SELECT running FROM tb_running WHERE type='" . $t . "' and year ='" . $_str . "' ";
        $result = $this->ExecuteData($sql);

        $cnt = $result->RecordCount();

        if ($cnt == 0) {
            $sqlInser = "Insert Into tb_running (type, year, running) values ('" . $t . "', '" . $_str . "', 1)";
            $this->ExecuteData($sqlInser);
            return $t . $_str . '0001';
        } else {
            $row = $result->FetchRow();
            $sqlupdate = "update tb_running set running=running+1 where type='" . $t . "' and year ='" . $_str . "'";
            //print_r($sqlupdate);
            $this->ExecuteData($sqlupdate);
            $no = $row["running"] + 1;
            return $t . $_str . str_repeat('0', 4 - strlen($no)) . $no;
        }
    }
    function loadPurchase($rq='',$no = '', $status = 0, $df = '', $dt = '', $name = '', $id = 0, $uid=0 , $supplier=0,$admin_flage=0) {
        $sqlscript = " SELECT r.id , r.rq_no , r.po_no ,DATE_FORMAT(purchange_date,'%d/%m/%Y') purchasedate , r.amt,r.discount, r.total"
                . " , s.name as statusname,r.status_po as status , r.remark, u.name as request_by , r.supplier, sup.name as supplier_name ";
        $sqlscript.= " FROM tb_purchase r ";
		$sqlscript.= " LEFT JOIN tb_supplier sup on sup.id = r.supplier " ;
        $sqlscript.= " INNER JOIN tb_status_purchase s on s.id = r.status_po and s.PO='Y' ";
		$sqlscript.= " LEFT JOIN tb_user u on u.id = r.createby " ;
        $sqlscript.= " WHERE 1=1 and r.isDelete =0 ";
		
		if ($supplier !=0){
			$sqlscript.= " and r.supplier =".$supplier;
		}
		
        if ($name != '') {
            $sqlscript.= " and u.name like '".$name."'" ;
        }
        if ($no !=''){
            $sqlscript.= " and r.po_no = '" . $no . "'";
            
        }
        if ($rq != '') {
            $sqlscript.= " and r.rq_no = '" . $rq . "'";
        }
        if ($status != 0) {
            $sqlscript.= " and r.status_po = " . $status;
        }
        if ($df != '') {
            $sqlscript.= " and r.purchange_date between '" . $df . "' and '" . $dt . "'";
        }
        if ($id != 0) {
            $sqlscript.= " and r.id = " . $id;
        }
		if ($uid !=0 && $admin_flage==0 ){
			 $sqlscript.= " and u.id = " . $uid;
		}
		
        $sqlscript.= " Order by r.purchange_date desc, r.status_po asc ";
	//	  print_r($sqlscript);
        $result = $this->ExecuteData($sqlscript);
        $this->rowCount = $result->RecordCount();
        return $result;
        
    }
    function loadRequest($no = '', $status = 0, $df = '', $dt = '', $name = '', $id = 0, $uid=0) {

        $sqlscript = " SELECT r.id , r.rq_no as req_no ,DATE_FORMAT(r.request_date,'%d/%m/%Y') requestdate , r.amt  , s.name as statusname,r.status_rq as status, r.remark , u.name as request_by ";
        $sqlscript.= " FROM tb_purchase r ";
        $sqlscript.= " LEFT JOIN tb_status_request s on s.id = r.status_rq ";
		$sqlscript.= " LEFT JOIN tb_user u on u.id = r.createby " ;
		
        $sqlscript.= " WHERE 1=1 and r.isDelete =0  ";
        if ($name != '') {
            $sqlscript.= " and u.name like '%".$name."%'" ;
        }
        if ($no != '') {
            $sqlscript.= " and r.rq_no = '" . $no . "'";
        }
        if ($status != 0) {
            $sqlscript.= " and r.status = " . $status;
        }
        if ($df != '') {
            $sqlscript.= " and r.request_date between '" . $df . "' and '" . $dt . "'";
        }
        if ($id != 0) {
            $sqlscript.= " and r.id = " . $id;
        }
		if ($uid !=0 ){
			 $sqlscript.= " and u.id = " . $uid;
		}
        $sqlscript.= " Order by r.request_date desc, r.status_rq asc ";
		//print_r($sqlscript);
        $result = $this->ExecuteData($sqlscript);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
	
	function load_pay_stock($no = '',$ro='', $status = 0, $df = '', $dt = '', $name = '', $id = 0) {
        $sqlscript = " SELECT r.id  , r.po_no ,DATE_FORMAT(r.purchange_date,'%d/%m/%Y') purchasedate , u.name as orderby
                    , r.ro_no ,DATE_FORMAT(r.receive_date,'%d/%m/%Y') receivedate , u2.name as receiveby
                    , r.amt, r.discount, r.total
                    , IFNULL((CASE WHEN r.pay_by='0' THEN 'เงินสด'  
							WHEN r.pay_by='1' THEN 'เช็ค'      
							WHEN r.pay_by='2' THEN 'ธนาคาร'    ELSE ''  END),'') as pay_by , r.remark 
					, IFNULL( DATE_FORMAT(r.pay_date,'%d/%m/%Y'),'') paydate 
					,sp.name as suppliername
                    FROM tb_purchase r  
                    LEFT JOIN tb_user u on u.id = r.createby
                    LEFT JOIN tb_user u2 on u2.id= r.updateby
					LEFT JOIN tb_supplier sp on sp.id = r.supplier
                    WHERE 1=1 and r.status_ro =5 and r.isDelete =0  ";
        if ($name != '') {
             $sqlscript.= " and u.name like '".$name."'" ;
        }
        if ($no != '') {
            $sqlscript.= " and r.po_no = '" . $no . "'";
        }
        if ($ro != '') {
            $sqlscript.= " and r.ro_no = '" . $ro . "'";
        }
        if ($status != 0) {
          //  $sqlscript.= " and r.status_ro = " . $status;
        }
        if ($df != '') {
            $sqlscript.= " and r.purchange_date between '" . $df . "' and '" . $dt . "'";
        }
        if ($id != 0) {
            $sqlscript.= " and r.id = " . $id;
        }
        $sqlscript.= " Order by  r.status_ro asc ,r.purchange_date desc";
		//print_r($sqlscript);
        $result = $this->ExecuteData($sqlscript);
        $this->rowCount = $result->RecordCount();
        return $result;
        
    }
    function loadreceive($no = '',$ro='', $status = 0, $df = '', $dt = '', $name = '', $id = 0) {
        $sqlscript = " SELECT r.id , r.rq_no , r.po_no ,DATE_FORMAT(r.purchange_date,'%d/%m/%Y') purchasedate , u.name as orderby
                    , ifnull(r.ro_no,'') as ro_no ,DATE_FORMAT(r.receive_date,'%d/%m/%Y') receivedate , u2.name as receiveby
                    , r.amt, r.discount, r.total
                    , s.name2 as statusname,r.status_ro as status , r.remark 
					,sp.name as suppliername , ifnull(r.pa_no,'') as pa_no
                    FROM tb_purchase r  
                    INNER JOIN tb_status_purchase s on s.id = r.status_ro and s.RO='Y'
                    LEFT JOIN tb_user u on u.id = r.createby
                    LEFT JOIN tb_user u2 on u2.id= r.receive_by
					LEFT JOIN tb_supplier sp on sp.id = r.supplier
                    WHERE 1=1 and r.isDelete =0 ";
        if ($name != '') {
             $sqlscript.= " and u.name like '".$name."'" ;
        }
        if ($no != '') {
            $sqlscript.= " and r.po_no = '" . $no . "'";
        }
        if ($ro != '') {
            $sqlscript.= " and r.ro_no = '" . $ro . "'";
        }
        if ($status != 0) {
            $sqlscript.= " and r.status_ro = " . $status;
        }
        if ($df != '') {
            $sqlscript.= " and r.purchange_date between '" . $df . "' and '" . $dt . "'";
        }
        if ($id != 0) {
            $sqlscript.= " and r.id = " . $id;
        }
        $sqlscript.= " Order by  r.status_ro asc ,r.purchange_date desc";
		//print_r($sqlscript);
        $result = $this->ExecuteData($sqlscript);
        $this->rowCount = $result->RecordCount();
        return $result;
        
    }
    function loadStock($n='',$t=0,$c=0,$v=''){
        $sql = "SELECT s.id , s.pid ,p.code , p.name, s.amt , t.name as typename ,p.cost, p.price 
                FROM  tb_stock s
                JOIN tb_product p on p.id = s.pid
                JOIN tb_product_type t on t.id = p.type" ; 
        $sql .=" WHERE 1=1 ";
        
        if ($n !='' ){
            $sql .= " and p.name like '%$n%' ";
        }
        if ($t !=0 ){
            $sql .= " and p.type =".$t;
        }
        if ($v!=0){
            if ($c==0){
                $sql .= " s.amt <=". $v;
            }else if ($c == 1){ 
                $sql .= " s.amt =". $v;
            }else {
                 $sql .= " s.amt >=". $v;
            }
        }
        $sql .=" order by p.name, p.type ";
        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
    function loadProduct($t) {
        $sql = " SELECT id,name,cost,price,ifnull(code,'') code  FROM tb_product Where type=" . $t . " and status='Y' order by name asc ";
        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
	function loadProduct_for_shipment() {
        $sql = " SELECT id,name,cost,price,code FROM tb_product Where type in (1,2) and status='Y' order by name asc ";
        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
	 function loadProductDetail_shipment($id){
         $sql = " SELECT  rd.id, p.code, p.name , rd.amt
					FROM tb_shipment_detail rd  
					JOIN tb_product p on p.id = rd.pid 
					JOIN tb_product_type t on t.id = p.type  
					WHERE 1=1 and rd.sh_id =".$id." order by rd.id asc ";


        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
        
    }
    function loadProductDetail_Purchase($id){
         $sql = " SELECT rd.id, p.code, po_id, p.name as productname , t.name as typename , rd.cost,rd.discount, rd.amt , ifnull(rd.amt_ro,rd.amt) as amt_ro
                    FROM tb_purchase_detail rd  
		  JOIN tb_product p on p.id = rd.pid  
		  JOIN tb_product_type t on t.id = p.type  
	 	 WHERE 1=1 and po_id =" . $id . " order by rd.id asc ";


        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
        
    }
    function loadCustomer(){
        $result = $this->ExecuteData("SELECT id, name   From tb_user Where status ='Y' Order by name");   
        $this->rowCount = $result->RecordCount();
        return $result;
    }
    function loadProductDetail($id) {
          
        $sql = " SELECT rd.id,  rd.po_id rq_id, p.name as productname , t.name as typename, rd.amt 
                FROM tb_purchase_detail rd  
		  JOIN tb_product p on p.id = rd.pid  
		  JOIN tb_product_type t on t.id = p.type  
	 	 WHERE 1=1 and po_id =" . $id . " order by rd.id asc ";


        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
    function loadShipment($code='',$p='',$df='',$dt='',$n='',$id=0){
          $sql = " SELECT sh.id , u.name , sh.amt, sh.remark ,DATE_FORMAT(sh.shipment_date,'%d/%m/%Y') shipmentdate
                    FROM tb_shipment sh
                    JOIN tb_employee u on u.id = sh.uid
                    WHERE 1=1 and del_flag='N' ";
         if ($id !=0 ){
             $sql .= " and sh.id =".$id;
         } 
         if ($df !=''){
             $sql .= " and shipment_date between '".$df."' and '".$dt."'";
         }
         if ($n !=''){
             $sql .=" u.name like '%".$n."%' ";
         }
         if ($code !='' || $p !=''){
              $sql .= " AND sh.id iN (SELECT sh_id From tb_shipment_detail sd 
                                                    JOIN tb_product p on p.id = sd.pid WHERE 1=1 ";
              if ($code !=''){
                    $sql.=" and p.code = '".$code."'  ";
               }
               if ($p !=''){
                   $sql.=" and p.name like '%".$p."%'  ";
               }
               $sql.=")";
         }
		 
         $sql .=" ORDER BY sh.shipment_date desc ";

        $result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
        return $result;
    }
    function getRowCount() {

        return $this->rowCount;
    }

    function getPurchase() {

        $sqlscript = "select id, name from tb_status_purchase where 1=1 and PO='Y' ";

        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        while ($row = $result->FetchRow()) {
            $ar[$row["name"]] = $row["id"];
        }
        return $ar;
    }
    function getReceive(){
        
        $sqlscript = "select id, name2 as name from tb_status_purchase where 1=1 and RO='Y' ";

        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        while ($row = $result->FetchRow()) {
            $ar[$row["name"]] = $row["id"];
        }
        return $ar;
    }
    function getRequest() {

        $sqlscript = "select id, name from tb_status_request where 1=1 and status='Y' ";
        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        while ($row = $result->FetchRow()) {
            $ar[$row["name"]] = $row["id"];
        }
        return $ar;
    }
    function getRoStatusById($id){
         $sqlscript = "select id, name2 as name from tb_status_purchase where 1=1 and  RO='Y' and id=" . $id;

        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        $row = $result->FetchRow();
        return $row['name'];
        
    }
    function getPoStatusById($id) {
        $sqlscript = "select id, name from tb_status_purchase where 1=1 and id=" . $id;

        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        $row = $result->FetchRow();
        return $row['name'];
    }
    function getRequestStatusById($id) {
        $sqlscript = "select id, name from tb_status_request where 1=1 and id=" . $id;

        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        $row = $result->FetchRow();
        return $row['name'];
    }

    function getProductType($status = 'Y') {
        $sqlscript = "select id, name from tb_product_type where 1=1 ";
        if ($status != '') {
            $sqlscript .= " and status = '" . $status . "' ";
        }
        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        while ($row = $result->FetchRow()) {
            $ar[$row["name"]] = $row["id"];
        }
        return $ar;
    }
	function getSupplier(){
		$sqlscript = " SELECT id , name
							FROM tb_supplier WHERE status='Y' ";
       
        $sqlscript .=" Order by id asc ";

        $result = $this->ExecuteData($sqlscript);
        while ($row = $result->FetchRow()) {
            $ar[$row["name"]] = $row["id"];
        }
        return $ar;
	}
    function InsertPurchaseData($val){
         if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT po_no, amt,discount, total,   status_po ,supplier, remark ,purchange_date,createdate,createby FROM tb_purchase where 1=2 ", $val);
            $this->ExecuteData($sqlInsert);
            $id = $this->getLastID();
            return $id;
        }       
    }
    function InsertShipment($val){
         if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT uid, amt, shipment_date , remark ,createdate,createby FROM tb_shipment where 1=2 ", $val);
            $this->ExecuteData($sqlInsert);
            $id = $this->getLastID();
            return  $id;
        }  
    }
    function InsertShipmentDetail($val){
        if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT sh_id, pid, amt   FROM tb_shipment_detail where 1=2 ", $val);
            //print_r($sqlInsert);
            $this->ExecuteData($sqlInsert);
        }
        
    }
     function InsertPurchaseDataDetail($val) {
        if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT po_id, pid, amt,cost, discount  FROM tb_purchase_detail where 1=2 ", $val);
            $this->ExecuteData($sqlInsert);
        }
    }
    
     function UpdateReceiveDataDetail($val) {
        if (isset($val)) {
		
            $this->ExecuteData(" Update tb_purchase_detail set amt_ro= ".$val['amt']." where id=".$val['id']);
			$sql = " SELECT s.pid , s.amt + amt_ro as total
					 FROM tb_purchase_detail pd
					 JOIN tb_stock s on s.pid = pd.pid
					 WHERE pd.id =".$val['id'];
			 $result =$this->ExecuteData($sql);
			 if ($result->RecordCount() > 0 ){
				$row = $result->FetchRow();
				$sqlupdate = " Update tb_stock SET amt=".$row['total']." WHERE pid=".$row['pid'];
				$this->ExecuteData($sqlupdate);
			 }else {
				 $sqlInsert = "INSERT INTO tb_stock (pid, amt)
					 SELECT pd.pid , amt_ro 
					 FROM tb_purchase_detail pd
					 LEFT JOIN tb_stock s on s.pid = pd.pid
					 WHERE pd.id =".$val['id'];
				$this->ExecuteData($sqlInsert);	
			 }
        }
    }
    
    //iNsert Requset data
    function InsertData($val) {
        if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT rq_no, amt, status_rq , remark ,request_date,createdate,createby FROM tb_purchase  where 1=2 ", $val);
            $this->ExecuteData($sqlInsert);
            $id = $this->getLastID();
            return $id;
        }
    }

    function InserDataDetail($val) { 
        if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT po_id, pid, amt  FROM tb_purchase_detail where 1=2 ", $val);
            $this->ExecuteData($sqlInsert);
        }
    }
	function update_status_purchage($id, $status,$userid){
		$script="";
		if ($status=="3"){
			$script = ", status_ro=".$status ;
		}
		$sql = " update tb_purchase set status_po =".$status." ". $script ." ,updatedate=now() ,  updateby=".$userid."  Where  id=".$id;
		$this->ExecuteData($sql);
	}
	function update_status_request($id,$status,$userid){
		$ro="";
		if ($status==5){
			$ro = $this->getRunning("PO");
			$sql = " update tb_purchase set status_rq =".$status.", po_no='".$ro."' , purchange_date=now(), status_po=2, updatedate=now() ,  updateby=".$userid." Where  id=".$id;
		}
		else{
			$sql = " update tb_purchase set status_rq =".$status.",updatedate=now() ,  updateby=".$userid."  Where  id=".$id;
		}
		
		$this->ExecuteData($sql);
	}
    function update_stock($id,$pid, $amt){
        $sql = " Update tb_stock set amt= ".$amt ." where id=".$id." and pid=".$pid;
         $this->ExecuteData($sql);
    }
	function updateReceiveNo($id, $re_no){
		$sql = " update tb_purchase set ro_no='".$re_no."' where id=".$id;
		$this->ExecuteData($sql);
	}
	function updatePayNo($id, $pa_no){
		$sql = " update tb_purchase set pa_no='".$pa_no."' where id=".$id;
		$this->ExecuteData($sql);
	}
    function updateReciveData($id,$val){
            if(isset($val)){
                $sqlUpdate=$this->UpdateSqlScript("SELECT receive_date,total ,status_ro , receive_by  ,updatedate,updateby  FROM tb_purchase where id='".$id."'" ,$val);
                 $this->ExecuteData($sqlUpdate);
                // return $sqlUpdate;
            }
    }
	function update_pay_by($id, $pay){
			$sql = " Update tb_purchase set pay_by= '".$pay ."' , pay_date=now() where id=".$id;
			//print_r($sql);
         $this->ExecuteData($sql);
	}
    function updateData($id, $val) {
        if (isset($val)) {
            $sqlUpdate = $this->UpdateSqlScript("SELECT  code,name,title,date_in, did, education,status, updatedate,updateby  FROM " . $this->table_name . " where id='" . $id . "'", $val);
            $this->ExecuteData($sqlUpdate);
            // return $sqlUpdate;
        }
    }
    function deleteShipmentDetail($id){
         $sqlDelete = "Delete FROM tb_shipment_detail where sh_id=" . $id ;
            $this->ExecuteData($sqlDelete);
    }
    function deleteShipment($id){
        $sql = "UPDATE  tb_shipment set del_flag='Y' where id=".$id;
        $this->ExecuteData($sql);
    }
    function deleData($id) {
        if (isset($id)) {
            $sqlDelete = "UPDATE tb_purchase SET isDelete=1  where id='" . $id . "'";
            $this->ExecuteData($sqlDelete);
			
			$this->deleData_detail($id);
            return 1;
        }
    }
	  // function deleData_detail($id) {
        // if (isset($id)) {
            // $sqlDelete = "Delete FROM tb_purchase_detail where po_id='" . $id . "'";
            // $this->ExecuteData($sqlDelete);
            // return 1;
        // }
    // }
    function StockUpdate($pid,$amt,$user_id=0){
        $sql= " Update tb_stock Set amt=amt-".$amt .",updatedate=now(),updateby=".$user_id. "  where pid=".$pid;
        $this->ExecuteData($sql);
        
    }
    function CheckStock($pid,$amt){
        $sql = " SELECT amt FROM tb_Stock where pid=".$pid." and amt>=".$amt;
        $result= $this->ExecuteData($sql);
       return $result->RecordCount();// 1: can do //0; cannot
    }
	function findProductByCode($code){
		$sql = " SELECT ifnull(p.price ,0) as price , p.name , p.code , ifnull(st.amt,0) as amt,p.id
					FROM tb_stock st
					JOIN tb_product p on p.id = st.pid
					WHERE 1=1 and p.code ='".$code."' ";
		
		$result= $this->ExecuteData($sql);
		$this->rowCount = $result->RecordCount();
        return $result;
	}
	function findProductByID($id){
		$sql = " SELECT ifnull(p.price ,0) as price , p.name , p.code , ifnull(st.amt,0) as amt,p.id
					FROM tb_stock st
					JOIN tb_product p on p.id = st.pid
					WHERE 1=1 and p.id =".$id;
		
		$result= $this->ExecuteData($sql);
		$this->rowCount = $result->RecordCount();
        return $result;
	}
	function AddSudentProduct_header($val){
		if(isset($val)){
			$sql_insert = $this->InsertSqlScript("SELECT code ,student_id, year , term, amt, total, createdate, createby 
													FROM tb_student_product WHERE 1=2",$val);
			
			$id = $this->ExecuteDataAndGetID($sql_insert);
            return $id;
		}
	}
	function AddToStudentProduct($val){
		 if (isset($val)) {
            $sqlInsert = $this->InsertSqlScript("SELECT  product_id, amount, price,student_product_id
													FROM tb_student_product_detail
													WHERE 1=2", $val);
			//print_r($sqlInsert);
            $this->ExecuteData($sqlInsert);
        }
	}
	function loadStudentStockHistory($id){
		$sql = "  SELECT sp.id,sp.code , DATE_FORMAT( sp.createdate , '%d/%m/%Y') as create_date 
					,year, term,   sp.amt
				  , ifnull(sp.total,0) as total
					, u.name
				FROM tb_student_product sp
				JOIN tb_user u on u.id = sp.createby
				where sp.student_id = ".$id ." order by sp.createdate desc ";
		$result= $this->ExecuteData($sql);
		$this->rowCount = $result->RecordCount();
        return $result;
	}
	function getStockHistoryDetail($id){
	
		$sql = " SELECT p.code , p.name , spd.amount , spd.price
				FROM tb_student_product sp
				JOIN tb_student_product_detail spd on spd.student_product_id = sp.id 
				LEFT JOIN tb_product p on p.id = spd.product_id ";
		$sql .= " where sp.id = ".$id;
		
		$result= $this->ExecuteData($sql);
		$this->rowCount = $result->RecordCount();
        return $result;
	}

}

?>
